#set( $symbol_pound = '#' )
#set( $symbol_dollar = '$' )
#set( $symbol_escape = '\' )
package ${package}.biz.helper;

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.util.EntityUtils;

import java.io.IOException;
import java.util.HashMap;

/**
 * Created by well on 16/6/20.
 */
public class HttpResult {

    private String cookie;

    private int statusCode;

    private HashMap<String, Header> headerAll = new HashMap<String, Header>();

    private HttpEntity httpEntity;


    public String getCookie() {
        return cookie;
    }

    public void setCookie(String cookie) {
        this.cookie = cookie;
    }

    public int getStatusCode() {
        return statusCode;
    }

    public void setStatusCode(int statusCode) {
        this.statusCode = statusCode;
    }

    public HashMap<String, Header> getHeaderAll() {
        return headerAll;
    }

    public void setHeaders(Header[] headers){
        headerAll = new HashMap<String, Header>();
        for (Header header : headers) {
            headerAll.put(header.getName(), header);
        }

    }

    public void setHeaderAll(HashMap<String, Header> headerAll) {
        this.headerAll = headerAll;
    }

    public HttpEntity getHttpEntity() {
        return httpEntity;
    }

    public void setHttpEntity(HttpEntity httpEntity) {
        this.httpEntity = httpEntity;
    }

    public String getResponseString(){
        if(httpEntity == null){
            return null;
        }
        try {
            return EntityUtils.toString(httpEntity);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    public String getResponseStringUTF8(){
        if(httpEntity == null){
            return null;
        }
        try {
            return EntityUtils.toString(httpEntity,"UTF-8");
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
